package com.shanhai.wallpapers.network.repository

import androidx.paging.Pager
import androidx.paging.PagingConfig
import androidx.paging.liveData
import com.shanhai.wallpapers.data.PexelsPagingSource
import com.shanhai.wallpapers.fragments.download.DownloadResult
import com.shanhai.wallpapers.network.remote.PexelsRemoteDataSource
import kotlinx.coroutines.flow.Flow
import java.io.File

class PexelsRepository(private val pexelsRemoteDataSource: PexelsRemoteDataSource) {
    fun getWallPapers(query: String) = Pager(
        config = PagingConfig(
            pageSize = 20,
            maxSize = 100
        ),
        pagingSourceFactory = { PexelsPagingSource(pexelsRemoteDataSource, query) }
    ).liveData

    fun downloadWallpaper(url: String, directory: File): Flow<DownloadResult> {
        return pexelsRemoteDataSource.downloadWallpaper(url, directory)
    }
}